/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2021年5月28日
 */
package com.massyframework.beanskin.test;

import java.util.HashMap;
import java.util.Map;

/**
 * 配置参数构建器
 * @author huangkh
 *
 */
public final class ConfigurationBuilder {
	
	private Map<String, String> configuration;

	/**
	 * 
	 */
	public ConfigurationBuilder() {
		this.configuration = new HashMap<>();
	}
		
	/**
	 * 添加配置参数
	 * @param name {@link String},参数名
	 * @param value {@link String},参数值
	 * @return {@link ConfigurationBuilder}
	 */
	public ConfigurationBuilder addConfig(String name, String value) {
		this.configuration.put(name, value);
		return this;
	}
	
	/**
	 * 尝试添加参数，如果参数已存在则跳过
	 * @param name {@link String},参数名
	 * @param value {@link String},参数值
	 * @return {@link ConfigurationBuilder}
	 */
	public ConfigurationBuilder addConfigIfAbsent(String name, String value) {
		this.configuration.putIfAbsent(name, value);
		return this;
	}
	
	/**
	 * 添加配置参数
	 * @param value {@link Map}
	 * @return {@link ConfigurationBuilder}
	 */
	public ConfigurationBuilder addConfig(Map<String, String> value) {
		if (value != null) {
			this.configuration.putAll(value);
		}
		
		return this;
	}
	
	public Map<String, String> build(){
		return new HashMap<>(this.configuration);
	}

}
